// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    songs: []
  },

  onLoad: function (options) {

  },
  async onSubmit(event) {
    var keyword = event.detail.value.name;
    var module = await import("../../utils/util");
    var searchRes = await module.musicHttp.searchSong(keyword);
    this.handleHttpData(searchRes);
  },
  handleHttpData(res) {
    var arr = [];
    res.data.result.songs.forEach(async item => {
      var { id, name } = item;
      var artistsName;
      item.artists.forEach(item => {
        artistsName = item.name;
      })
      var module = await import("../../utils/util");
      var detailRes = await module.musicHttp.searchDetail(id);
      detailRes.data.songs.forEach(item => {
        arr.push({id, name, artistsName, picUrl: item.al.picUrl });
        this.setData({ songs: arr })
      })
    })
  }
})